package me.dr0n3.skyTravel;

import java.io.Serializable;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

/**
 * @author dr0n3
 * @date 21.03.2012 
 */

public class Cube implements Serializable
{
    // <editor-fold defaultstate="collapsed" desc="Variablen">
    private SerializableLocation loc1;
    private SerializableLocation loc2;
    public SerializableLocation locAppear;
    // </editor-fold>
    
    public Cube(Location x, Location y)
    {
        loc1 = new SerializableLocation(x);
        loc2 = new SerializableLocation(y);
    }
    
    public boolean isInCube(Player player)
    {
        Location loc = player.getLocation();
        double locx = loc.getX();
        double locy = loc.getY();
        double locz = loc.getZ();
        World world = loc1.getWorld();
        double loc1x = loc1.getX();
        double loc1y = loc1.getY();
        double loc1z = loc1.getZ();
        double loc2x = loc2.getX();
        double loc2y = loc2.getY();
        double loc2z = loc2.getZ();    
        
        //player.sendMessage(player.getWorld().getName() + " : " + world.getName());
        if(player.getWorld().getName().equalsIgnoreCase(world.getName()))
        {
            //if player has right y coordinate
            if((locy >= loc1y && locy <= loc2y) || (locy <= loc1y && locy >= loc2y))
            {
                //if player has right x coordinate
                if((locx >= loc1x && locx <= loc2x) || (locx <= loc1x && locx >= loc2x))
                {
                    //if player has right z coordinate
                    if((locz >= loc1z && locz <= loc2z) || (locz <= loc1z && locz >= loc2z))
                    {
                        //player.sendMessage("Y: " + locy + ":" + loc1y + ":" + loc2y);
                        return true;
                    }
                }
            }
        }
        
        return false;
    }
}
